package com.ostrich.cloud.ostrichBusinessWeb.app.Api;

import com.ostrich.cloud.ostrichBusinessWeb.app.component.WebSocketServer;
import com.ostrich.cloud.ostrichGoodsSercice.model.Dto.GoodsDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
public class TestController {


    @ResponseBody
    @RequestMapping("/socket/push/{cid}")
    public Map pushToWeb(@PathVariable String cid, String message) {
        Map<String,Object> result = new HashMap<>();

        GoodsDto goodsDto = new GoodsDto();
        goodsDto.setBusinessmanId(1);
        goodsDto.setGoodsPrice(new BigDecimal(121.2));
        goodsDto.setGoodsImg("dqwdqwd");
        try {
            WebSocketServer.sendInfo(goodsDto, cid);
            result.put("code", cid);
            result.put("msg", message);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
